Ext.define('SRMT.controller.artifact-list.ArtifactList', {
	extend: 'Ext.app.Controller',
	
	views:['artifact-list.ArtifactList'],
	
	stores:['SRMT.store.ArtifactList'],
	
	init: function() {
		this.control({
			'srmtArtifactList': {
				itemdblclick: this.onItemDblClick,
				itemcontextmenu: this.onItemContextMenu
			}
		});
	},
	
	onItemDblClick: function(view, record, item, index, e, eOpts) {
		
	},
	
	onItemContextMenu: function(view, record, item, index, e, eOpts) {
		e.preventDefault();
		console.log('Right click');
	},
	
	getArtifactListByFolder: function(folderid) {
		var mystore = this.getStore('SRMT.store.ArtifactList');
		var req = Ext.Ajax.request({
			url: 'php/module/artifact_list/load_artifacts_by_folder.php',
			method: 'POST',
			params: {
				folder_pk: folderid
			},
			success: function(response) {
				mystore.loadData(Ext.JSON.decode(response.responseText), false);
			},
			failure: function() {
				console.log('Get REQ fail'+folderid);
			}
		});
		
	},
	
	getArtifactListByProject: function(projectId) {
		var mystore = this.getStore('SRMT.store.ArtifactList');
		var req = Ext.Ajax.request({
			url: 'php/module/artifact_list/load_artifacts_by_project.php',
			method: 'POST',
			params: {
				project_pk: projectId
			},
			success: function(response) {
				mystore.loadData(Ext.JSON.decode(response.responseText), false);
			},
			failure: function() {
				console.log('Get REQ fail'+projectId);
			}
		});
		
	}
});